// 原材料出库查询 -- wzhg
import React, { Component } from 'react'
import {ListBox} from '../../../components'
import { Modal } from 'antd';
import AddPage from './addPage'
import ListDetail from './ListDetailPage.js'
import { fetchData } from '../../../components/AjaxConsumer'
const confirm = Modal.confirm;

export default class SearchRawHandOut extends Component{
    constructor(props) {
        super(props);
        this.state = {
            visible: false
        }
        //行操作列表-已弃用
        this.rowOperation = [

        ];
        //header 操作列表111
        this.headerOperation = [
            //{
            //    handleName: 'add',
            //    showName: '新增',
            //    iconClass: 'plus'
            //}
            //,
            {
                handleName: 'create',
                showName: '创建',
                iconClass: 'plus',
                permission: 'pro-jy-add'
            },{
                handleName: 'delete',
                showName: '删除',
                iconClass: 'delete',
                permission: 'pro-jy-del'
            },{
                handleName: 'createBar',
                showName: '条码生成--按单',
                iconClass: 'barcode',
                permission: 'pro-jy-createid'
            },{
                handleName: 'info',
                showName: '条码详情',
                iconClass: 'info'
            }
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        // foreverHidden永久隐藏
        this.tableColumn = {
            storageKey: 'checkInId',
            data: [
                {
                    showName: 'checkInId',
                    columnName: 'checkInId',
                    columnHidden:true,
                    foreverHidden: true
                },
                {
                    showName: '登记单号',
                    columnName: 'checkInNo',
                    columnWidth: 150
                },{
                    showName: '合同编号',
                    columnName: 'contractNo',
                    columnWidth: 130
                },{
                    showName: '型号',
                    columnName: 'model',
                    columnWidth: 130
                },{
                    showName: '型号描述',
                    columnName: 'modelDesc'
                },{
                    showName: '型号类型',
                    columnName: 'modelType'
                },{
                    showName: '登记数量（个）',
                    columnName: 'amount',
                    columnWidth: 120
                },{
                    showName: '入库数量（个）',
                    columnName: 'inAmount',
                    columnWidth: 120
                },{
                    showName: '是否生成条码',
                    columnName: 'userDefined2',
                    showOption:[
                        {
                            optionKey:'0',
                            optionShow:'否'
                        },{
                            optionKey:'1',
                            optionShow:'是'
                        }
                    ],
                    columnWidth: 140
                },{
                    showName: '创建时间',
                    columnName: 'gmtCreate',
                    columnWidth: 140
                }
            ]
        };
        //搜索属性配置，如果字段不配置，默认是input搜索
        // 搜索类型：
        //      1、输入框 type='input'， 默认
        //      2、时间 type='date'
        //      3、数字 type='number'
        //      4、下拉框 type='select'
        //      5、下拉框 type='disabled'
        this.searchComponentData = [
            {
                showName: '型号类型',
                name: 'modelType',
                type: 'select',
                optionList: [//下拉框的信息
                ]
            },
            {
                showName: '是否生成条码',
                name: 'userDefined2',
                type: 'select',
                optionList: [//下拉框的信息
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'否'
                    },{
                        optionKey:'1',
                        optionShow:'是'
                    }
                ]
            },
            {
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax',
                minName:'gmtCreateMin',
                showTime:'1'
            }
        ];

    }

    // 行操作
    rowHandles = (strHandles, rowObj) => {
        if(strHandles === 'add'){
            this.addHandle();
        }else if(strHandles === 'create'){
            this.createHandle(rowObj);
        }else if(strHandles === 'delete'){
            this.deleteHandle(rowObj);
        }if(strHandles == 'doubleClick'){
            this.infoHandle(rowObj);
        }if(strHandles == 'info'){
            this.infoHandle(rowObj);
        }else if(strHandles === 'createBar'){
            this.createBarHandle(rowObj);
        }
    }

    addHandle = () => {
        this.setState({
            formData:{},
            submitUrl:'/wmsrest/raw/rawHandOut/createOutOrder'
        })
        this.showModal();
    }

    createHandle = () => {
        this.refs.addPage.addHandle();
    };

    // editHandle = (rowObj) => {
    //     // code不可编辑
    //     this.refs.rawEdit.getFormData[1].disable=true;
    //     if(rowObj.length == 0){
    //         Modal.error({
    //             title: '错误提示',
    //             content: '请选择一条数据',
    //         });
    //     }else if(rowObj.length > 1){
    //         Modal.error({
    //             title: '错误提示',
    //             content: '只能选择一条数据',
    //         });
    //     }else{
    //         this.refs.rawEdit.editHandle(rowObj[0].data);
    //     }
    // }

    createBarHandle = (rowObj) => {
         if(rowObj.length == 0){
             Modal.error({
                 title: '错误提示',
                 content: '请选择一条数据',
             });
         }else if(rowObj.length > 1){
             Modal.error({
                 title: '错误提示',
                 content: '只能选择一条数据',
             });
         }else{
             let checkInNo = rowObj[0].data.checkInNo;
             const options = {
                 url: '/product/intowarehouse/checkIn/barcode/create',
                 condition: {checkInNo: checkInNo}
             };
             let _that = this;
             confirm({
                 title: '是否生成条码？',
                 onOk() {
                     fetchData(_that, options, _that.refreshHandle);
                     console.log("------------生成条码操作------------------")
                 },
                 onCancel() {
                     console.log("取消了生成条码操作")
                 },
             });
         }
     }

    deleteHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            let checkInId = rowObj[0].data.checkInId;
            const options = {
                url: '/product/intowarehouse/checkIn/del',
                condition: {checkInId: checkInId}
            };

            let _that = this;
            confirm({
                title: '是否删除？',
                onOk() {
                    fetchData(_that, options, _that.refreshHandle);
                    console.log("------------删除操作------------------")
                },
                onCancel() {
                    console.log("取消了删除操作")
                },
            });
        }
    }

    infoHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.listDetail.editHandle(rowObj[0].data);
        }
    };

    showModal = () => {
        this.setState({
            visible: true
        });
    }

    handleCancel = () => {
        this.setState({
            visible: false
        });
        this.refreshHandle();
    }

    //刷新列表
    refreshHandle = () => {
        this.refs.rawHandOutQueryList.refreshHandle();
    }

    componentWillMount() {
        const dicType = 'model_type_p';
        const options = {
            url: '/base/dic/get/' + dicType,
            type: 'get',
            condition: {}
        };
        //先写死，后面再改
        fetchData(this, options, this.dicInitCallBackHandle);
    }

    //下拉框 初始化
    dicInitCallBackHandle = (resData) => {
        //alert('resData' + JSON.stringify(resData, null, 4));
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map((e, index) => {
            let tmp = {};
            tmp.optionKey = e.dicCode;
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });
        //alert('optionList' + JSON.stringify(optionList, null, 4));
        this.tableColumn.data[5].showOption = optionList;
        this.searchComponentData[0].optionList = optionList;
        //this.setState({
        //    tableColumn: this.tableColumn,
        //    searchComponentData: this.searchComponentData
        //})

    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <div>
                <ListBox
                    title="成品积压库存登记任务查询"
                    ref = 'rawHandOutQueryList'
                    isHideLeft={isHideLeft}
                    tableColumnData = {this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url = '/product/intowarehouse/checkIn/list'
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    headerOperation = {this.headerOperation}
                    isRowSingle = "true"
                />
                <AddPage
                    ref="addPage"
                    refreshHandle = {this.refreshHandle}
                />

                <ListDetail
                    ref="listDetail"
                    refreshHandle = {this.refreshHandle}
                />

            </div>
        )

    }

}